//
//  UIImageView+WebImage.swift
//  仿微博
//
//  Created by apple on 2016/12/27.
//  Copyright © 2016年 apple. All rights reserved.
//

import SDWebImage


extension UIImageView {

    /// 隔离 SDWebImage  设置图像函数
    ///
    /// - Parameters:
    ///   - urlString: urlString
    ///   - placeholderImage: 占位图像
    ///   - isAvatar: 是否是头像
    
    func cz_setImage(urlString: String?, placeholderImage: UIImage?, isAvatar: Bool = false){
    
    //处理 URL
        
        guard let urlString = urlString,
            let url = URL(string: urlString) else {
            image = placeholderImage
            return
        }
        //可选项 只是用在 Swift  OC 有的时候用 ！ 同样可以传入 nil
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { [weak self](image, _, _, _) in
       //完成回调  - 判断 是否是头像
            if isAvatar {
            
          self?.image = image?.cz_avatarImage(size: self?.bounds.size)
            
            }
            
            
        }
    }



}
